home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16556 < prev    next >
Encoding:
Text File  |  1996-08-05  |  4.0 KB  |  112 lines

  1. Path: news.compuserve.com!newsmaster
  2. From: Ed Howland <102233.3621@compuserve.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Help - ERROR: Use C++ with iostream.h - ???
  5. Date: Thu, 11 Apr 1996 01:37:51 -0700
  6. Organization: CompuServe Incorporated
  7. Message-ID: <316CC4DF.1E64@compuserve.com>
  8. References: <31671633.33DD@inforamp.net> <N.040896.100149.11@ix.netcom.com> <milodDpK638.23E@netcom.com> <4kedrk$fv@nw002.infi.net>
  9. NNTP-Posting-Host: ad49-212.compuserve.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.01 (Win95; I)
  14.  
  15. This is probably due to a nameing convention difference between his 
  16. computer at school and home. Unix C programs are typically named with a 
  17. ".c" extension. C++ programs use an uppercase ".C" extension. If you 
  18. copy this file to a DOS floppy or download from an FTP site, to a 
  19. DOS/Windows machine, it will be copyied with a ".c" extension (or ".C") 
  20. but since case is irrelevant in DOS, most compilers will treat it as a C 
  21. program. You are right, it must be renamed.
  22.  
  23. Using ".cpp" for C++ files is usually OK, and avoids recognition 
  24. problems for you later on. Note, there is typically not a requirement 
  25. for header files to be named ".hpp", since these are interpreted as the 
  26. type of the current compilation unit (either .c or .cpp). Most older .h 
  27. files (like stdio.h) are now C++  - safe. So you can be sure that you 
  28. can include both C and CPP headers in your C++ code (although the other 
  29. case is not true.) 
  30.  
  31. Note that you can do this as well. If you have any older headers that 
  32. you want to include in your C++ source, do the following:
  33.  
  34.  
  35. ---- oldchdr.h ---------
  36. #ifndef INC_OLDCHDR_H
  37. #define INC_OLDCHDR_H
  38.  
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42.  
  43. /* Your old C declaration here
  44.  
  45.  
  46. #ifdef __cplusplus
  47. }
  48. #endif
  49. #endif
  50.  
  51.  
  52.  
  53.  
  54. This works under Unix and DOS and everywhere else. the define 
  55. "__cplusplus" is guaranteed to be true for C++ compilation units, and 
  56. false otherwise. The 'extern "C" { }'  will force anything in the braces 
  57. to emit non-name mangled symbols. Thus the linker will find and link to 
  58. your older C libraries.
  59.  
  60. So it is perfectly all right to name your headers with just ".h" for the 
  61. extenstion. Note that for new style headers in C++ (such as the 
  62. standard template library) the include statement skips the extension 
  63. altogether:
  64.  
  65. #include <template>
  66.  
  67. Read up on the use of namespaces, here.
  68.  
  69.  
  70. glenn wrote:
  71. > I used to have the same problem with my school programs. The problem
  72. > might be in the setup of the program. I don't know what compiler you
  73. > are using, but you need to specify where your lib files and include
  74. > files reside in your computer. If you are running a project from the
  75. > school computer, it could be in a different directory.
  76. > Glenn
  77. > milod@netcom.com (John DiCamillo) wrote:
  78. > >>> When I run a program I brought from schoo, that is properly formatted and
  79. > >>> runs on the UNIX/PowerPC system there, I get an error like "Use C++ with
  80. > >>> iostream.h". I even renamed the first character in the header file from
  81. > >>> an upper case "I" to a lower case "i". Any ideas?
  82. > >It probably means that your C++ compiler "thinks" its
  83. > >compiling a C program, not a C++ program.  Some compilers
  84. > >are picky about the filename extensions:
  85. > >  use *.cpp for C++ source files
  86. > >  use *.hpp for C++ header files
  87. > >Note: I'm not saying that files "should" be named a
  88. > >certain way, only that some compilers may insist on it.
  89. > >Also, there is usually a compiler setting to force the
  90. > >compiler to treat all input files as either C or C++
  91. > >source code.  Try the help system to find the appropriate
  92. > >incantation.
  93. > >--
  94. > >    ciao,
  95. > >    milo
  96. > >================================================================
  97. > >    John DiCamillo                         Fiery the Angels Fell
  98. > >    milod@netcom.com       Deep thunder rode around their shores
  99.  
  100. -- 
  101. Ed Howland                   | Where's the British Beef?
  102. Eagle Creek Systems          | Billy and Bobby up in a tree...
  103. Consultant to the Stars!     | Line Item Veto-I-N-G
  104. 102233.3621@compuserve.com   | No-No-NAFTA, says Ross P.
  105.